<template>
  <div class="register-form">
    <h2>注册</h2>
    <div class="form-group">
      <label for="username">用户名:</label>
      <input type="text" id="username" v-model="username" required>
    </div>
    <div class="form-group">
      <label for="password">密码:</label>
      <input type="password" id="password" v-model="password" required>
    </div>
    <div class="form-group">
      <label for="confirmPassword">确认密码:</label>
      <input type="password" id="confirmPassword" v-model="confirmPassword" required>
    </div>
    <button @click="handleRegister" class="register-button">注册</button>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  setup(props, { emit }) {
    const username = ref('')
    const password = ref('')
    const confirmPassword = ref('')

    const handleRegister = () => {
      // 这里可以添加注册逻辑,例如验证密码是否一致,然后调用API进行注册
      // 注册成功后,触发父组件的'register'事件
      emit('register')
    }

    return {
      username,
      password,
      confirmPassword,
      handleRegister
    }
  }
}
</script>

<style scoped>
.register-form {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  width: 300px;
}

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
}

input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.register-button {
  width: 100%;
  padding: 10px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.register-button:hover {
  background-color: #45a049;
}
</style>